package com.aabte.design2.structural.flyweight;

import java.util.Collection;
import java.util.LinkedList;

/**
 * 树（Tree）和森林（Forest）类是享元的客户端。如果不打算继续对树类进行开
 * 发，你可以将它们合并。
 *
 * @author Daniel
 * @version 1.0
 * @date 2020/5/3
 */
public class Forest {

    private Collection<Tree> trees = new LinkedList<>();

    public void plantTree(int x, int y, String name, String color, String texture) {
        // 获取享元对象
        TreeType treeType = TreeFactory.getTreeType(name, color, texture);
        Tree tree = new Tree(x, y, treeType);
        trees.add(tree);
    }

    public void draw() {
        for (Tree tree : trees) {
            tree.draw();
        }
    }

}
